<template>
  <div style="margin-top: 20px">
    <button @click="openPreview">打开预览</button>
    <!-- xurl/ops 可不在 props 传入，改为 open 时传参 -->
    <DocumentPreview ref="previewRef" />
  </div>
</template>

<script setup lang="ts">
import { onMounted, ref } from 'vue'
import DocumentPreview from '@/components/common/preview/DocumentPreview.vue'
import type { PreviewOptions } from '@/components/common/preview/types'

const previewRef = ref<{ open: (xurl?: string, ops?: PreviewOptions) => void; close: () => void } | null>(null)

const file = 'https://automatic-teach-1325795131.cos.ap-guangzhou.myqcloud.com//resource/1/2025-07-22_2749868917782434.md'
const xurl = 'https://view.xdocin.com/view?src=' + encodeURIComponent(file)
const ops: PreviewOptions = { watermark: 'EduAgentPro', saveable: true }

function openPreview() {
  previewRef.value?.open(file, ops) // 运行时传参
}
onMounted(()=>{
  console.log("@@@")
})
</script>

<style scoped>

</style>
